package com.yn.common.response.zy;


import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yn.common.enums.NextFlagEnum;
import com.yn.common.model.zy.OrganDepartment;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(value = "医院科室树结构")
public class OrganDepartmentTreeResponse {

    @ApiModelProperty(value = "科室ID",  example = "1")
    private Integer id;

    @ApiModelProperty(value = "科室名称", required = true, example = "科室名称")
    private String departmentName;

    @ApiModelProperty(value = "父级id", example = "0")
    private Integer parentId;

    @ApiModelProperty(value = "等级")
    private Integer level;

    @ApiModelProperty(value = "是否有下级")
    private Integer isNexFalg;

    @ApiModelProperty(value = "是否有下级字符串")
    private String isNexFalgStr;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @ApiModelProperty(value = "子级列表")
    @JsonInclude(JsonInclude.Include.NON_EMPTY) //属性为 空（""）[] 或者为 NULL 都不序列化
    private List<OrganDepartmentTreeResponse> child = new ArrayList<>();

    public static OrganDepartmentTreeResponse transform(OrganDepartment organDepartment) {

        OrganDepartmentTreeResponse organDepartmentTreeResponse = new OrganDepartmentTreeResponse();
        BeanUtil.copyProperties(organDepartment, organDepartmentTreeResponse);
        organDepartmentTreeResponse.setIsNexFalgStr(NextFlagEnum.getByCode(organDepartment.getIsNexFalg()).getName());
        return organDepartmentTreeResponse;
    }

}
